" My currently working version Vimrc
" I kept all other settings in plugins/settings directory
"
" Eddie Kao
" http://blog.eddie.com.tw
" eddie@digik.com.tw

runtime bundle/vim-pathogen/autoload/pathogen.vim
filetype off
call pathogen#incubate()
filetype plugin indent on
call pathogen#infect()
call pathogen#helptags()

" hit enter to cancel searched highlight
"noremap <CR> :nohlsearch<CR>

" select ALL
map <C-A> ggVG
nnoremap <space> <C-F>
nnoremap <S-space> <C-B>
let mapleader = ","
let g:mapleader = ","
" 永久撤销，Vim7.3 新特性
if has('persistent_undo')
    set undofile

    " 设置撤销文件的存放的目录
    if has("unix")
        set undodir=/tmp/,~/tmp
    else
        set undodir=d:/temp/
    endif
    set undolevels=1000
    set undoreload=10000
endif

" Diff 模式的时候鼠标同步滚动 for Vim7.3
if has('cursorbind')
    set cursorbind
end
" 跳过页头注释，到首行实际代码
func! GotoFirstEffectiveLine()
    let l:c = 0
    while l:c<line("$") && (
                \ getline(l:c) =~ '^\s*$'
                \ || synIDattr(synID(l:c, 1, 0), "name") =~ ".*Comment.*"
                \ || synIDattr(synID(l:c, 1, 0), "name") =~ ".*PreProc$"
                \ )
        let l:c = l:c+1
    endwhile
    exe "normal ".l:c."Gz\<CR>"
endf
" 直接查看第一行生效的代码
nmap <Leader>gff :call GotoFirstEffectiveLine()<cr>
map j <c-f>
map k <c-b>
map zz :close<cr>
let pascal_delphi=1
"let pascal_symbol_operator=1
map <Leader>mr :CtrlPMixed<cr>
"nmap Q :x<cr>
"autocmd BufEnter * call DoWordComplete()
nmap ww :!dict <cword><cr>
map <leader>ch :call SetColorColumn()<CR>
function! SetColorColumn()
  let col_num = virtcol(".")
  let cc_list = split(&cc, ',')
  if count(cc_list, string(col_num)) <= 0
    execute "set cc+=".col_num
  else
    execute "set cc-=".col_num
  endif
endfunction
if &diff
  nmap <F2> [c
  nmap <F3> ]c
endif
set nocp
" avoid key conflict
let g:SuperTabMappingForward = '<Plug>supertabKey'

" if nothing matched in xpt, try supertab
let g:xptemplate_fallback = '<Plug>supertabKey'

" xpt uses <Tab> as trigger key
let g:xptemplate_key = '<Tab>'

" " use <tab>/<S-tab> to navigate through pum. Optional
" let g:xptemplate_pum_tab_nav = 1

" " xpt triggers only when you typed whole name of a snippet. Optional
" let g:xptemplate_minimal_prefix = 'full'
let g:xptemplate_vars = "author=LiYaLei&email=caidaoli@gmail.com&@copyright=5179.cn"

set formatoptions+=mM
"set nobomb " 不使用 Unicode 签名
let g:fencview_autodetect = 0   "#打开文件时自动识别编码
"let g:fencview_checklines = 5 "#检查前后10行来判断编码
let g:ctrlp_user_command = {
  \ 'types': {
        \ 1: ['.git', 'cd %s && git ls-files -c -o'],
        \ 2: ['.hg', 'hg --cwd %s locate -I .'],
      \ },
  \ 'fallback': 'find %s -type f'
  \ }
